package org.geektimes.projects.dependency.servlet;

import org.geektimes.projects.microprofile.servlet.ApplicationContextListener;

import javax.annotation.Priority;
import java.util.Comparator;

/**
 * @author biwin
 */
public class PriorityComparator implements Comparator<ApplicationContextListener> {

    public static final PriorityComparator INSTANCE = new PriorityComparator();


    @Override
    public int compare(ApplicationContextListener o1, ApplicationContextListener o2) {
        int o1_value = o1.getClass().getDeclaredAnnotation(Priority.class).value();
        int o2_value = o2.getClass().getDeclaredAnnotation(Priority.class).value();
        return o1_value - o2_value;
    }
}
